package com.yanqu.road.server.logic.thread;

import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.pb.union.cross.CrossUnionProto;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.thirdparty.PlatformMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.utils.executor.GeneralTask;
import com.yanqu.road.utils.string.StringUtils;

public class CrossUnionModifyTask extends GeneralTask {

    long serverId;
    long playerId;
    private int type;         //0：联盟名称； 1：微信号； 2：qq号； 3：对外公告； 4：对内公告
    private String content;
    private String consume;

    public CrossUnionModifyTask(long serverId, long playerId, int type, String content, String consume) {
        super();
        this.serverId = serverId;
        this.playerId = playerId;
        this.type = type;
        this.content = content;
        this.consume = consume;
    }

    @Override
    public void doRun() {

        int ret = PlatformMgr.unionModify(serverId, playerId, type, content, consume);


        if(ret != 0){
            if(StringUtils.isNullOrEmpty(consume)) {
                UnionProto.UnionModifyRespMsg.Builder respMsg = UnionProto.UnionModifyRespMsg.newBuilder();
                respMsg.setRet(ret);
                MessageHelper.sendPacket(serverId, playerId, YanQuMessageUtils.buildMessage(Protocol.U_UNION_MODIFY, respMsg));
            }else {
                CrossUnionProto.UnionModifyCrossRespMsg.Builder respMsg = CrossUnionProto.UnionModifyCrossRespMsg.newBuilder();
                respMsg.setRet(ret);
                respMsg.setConsume(consume);
                MessageHelper.sendPacket(serverId, playerId, YanQuMessageUtils.buildMessage(Protocol.S_UNION_MODIFY_FROM_CROSS, respMsg));
            }
        }
    }
}
